/*
 * @Author: liuqiang
 * @Date: 2021-02-08 15:21:58
 * @Last Modified by: liuqiang
 * @Last Modified time: 2021-03-11 15:00:11
 */
const { initSuperUser } = require('./user');
const { readFileName } = require('../utils/tool');

const keys = readFileName(__dirname);

function initModels() {
  let promises = [];
  keys.forEach((key) => {
    const { sequelize } = require('./' + key);
    promises.push(sequelize.sync());
  });
  return new Promise((resolve, reject) => {
    Promise.all(promises)
      .then((res) => {
        initSuperUser();
        resolve();
      })
      .catch((err) => {
        console.error(err);
        reject(err);
      });
  });
}

module.exports = {
  initModels,
};
